package priv.pront.code.mati.province;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-11-15 16:41
 */
public class MC0138_吃外卖 {

    static int n, m;
    static int[] a;
    static int res = 0;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        a = new int[m];
        for (int i = 0; i < m; i++) a[i] = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            Arrays.sort(a);
            res += a[m - 1];
            a[m - 1] = a[m - 1] - 1;
        }
        System.out.println(res);
    }
}
